/**
 * @Author: 魏巍 <jswei>
 * @Date:   2018-08-10T20:33:46+08:00
 * @Email:  524314430@qq.com
 * @Filename: main.js
 * @Last modified by:   jswei
 * @Last modified time: 2018-08-28T04:34:32+08:00
 * @Copyright: free
 */

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import axios from 'axios'
import VueAxios from 'vue-axios'
import MintUI from 'mint-ui'
import 'mint-ui/lib/style.css'
import filter from './filters'
import tools from './tools'
import '@/assets/style/base.scss'
import '../static/iconfont/iconfont.css'
//import '@/assets/js/reset.js'
Vue.use(MintUI)
Vue.use(VueAxios, axios)
//注册全局过滤器
Object.keys(filter).forEach(key => {
  Vue.filter(key, filter[key])
})

//注册全局方法
Object.keys(tools).forEach(key => {
  Vue.prototype[key] = tools[key];
})

axios.interceptors.request.use(function (config) { //配置发送请求的信息
  //store.dispatch('SHOW_LOADING');
  return config;
}, function (error) {
  return Promise.reject(error);
});
axios.interceptors.response.use(function (response) { //配置请求回来的信息
  //store.dispatch('HIDE_LOADING');
  return response;
}, function (error) {
  return Promise.reject(error);
});

router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requiresAuth)) {
    let logined = localStorage.getItem('logined');
    if (!logined) {
      next({
        path: '/login',
        query: {
          redirect: to.fullPath
        }
      })
    } else {
      next()
    }
  } else {
    next()
  }
})

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
